/*
 * Filename    : SceneLogo.java
 * Projectname : CobaScene
 * Date        : Jan 1, 2013 , 9:00:42 PM 
 * 
 */

package com.example.cobascene.scene;

import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.util.color.Color;

import android.content.Context;

import com.example.cobascene.IManageableScene;
import com.example.cobascene.SceneManager;
import com.example.cobascene.Utils;
import com.example.cobascene.config.Game_Data;
import com.example.cobascene.config.Game_Define;
import com.example.cobascene.data.Graphic_Data;

public class SceneLogo extends Scene implements IManageableScene, Graphic_Data, Game_Data, Game_Define
{
	private BaseGameActivity	activity;
	private SceneManager		sm;
	private BitmapTextureAtlas	texLogo;
	private TextureRegion		regLogo;
	private Sprite				sprLogo;

	public SceneLogo(BaseGameActivity pActivity)
	{
		// TODO Auto-generated constructor stub
		activity = pActivity;

		sm = new SceneManager(activity);
		loadResources();
		applyResources();
		registerUpdateHandler();

	}

	@Override
	public void loadResources()
	{
		// TODO Auto-generated method stub
		texLogo = new BitmapTextureAtlas(activity.getTextureManager(), ANDROID_LOGO_TEX_WIDTH, ANDROID_LOGO_TEX_HEIGHT,
				Utils.getTextureOption());
		regLogo = BitmapTextureAtlasTextureRegionFactory.createFromAsset(texLogo, activity.getAssets(), ANDROID_LOGO,
				0, 0);
		texLogo.load();

	}

	@Override
	public void applyResources()
	{
		// TODO Auto-generated method stub
		setBackground(new Background(Color.WHITE));
		sprLogo = new Sprite(0, 0, regLogo, activity.getVertexBufferObjectManager());
		sprLogo.setPosition(RES_WIDTH / 2 - sprLogo.getWidth() / 2, RES_HEIGHT / 2 - sprLogo.getHeight() / 2);

		attachChild(sprLogo);

	}

	@Override
	public void registerUpdateHandler()
	{
		// TODO Auto-generated method stub
		this.registerUpdateHandler(new TimerHandler(2f, true, new ITimerCallback()
		{

			@Override
			public void onTimePassed(TimerHandler pTimerHandler)
			{
				// TODO Auto-generated method stub
				SceneLogo.this.unregisterUpdateHandler(pTimerHandler);
				sm.setScene(SceneManager.SCENE_MENU);

			}
		}));

	}

	@Override
	public void unloadResources()
	{
		// TODO Auto-generated method stub

	}

}
